﻿namespace BusinessLogicLayer
{
    using System;
    using System.Collections.Generic;
    using DataAccessLayer;

    /// <summary>
    /// Represents a collection of columns.
    /// For Tasks and UserStories it has 3 columns.
    /// For Projects it has 1 column.
    /// </summary>
    public class ColumnCollection
    {
        /// <summary>
        /// Amount of columns in column collection
        /// </summary>
        private readonly ColumnsAmount columnAmount;

        /// <summary>
        /// Array of Column instances
        /// </summary>
        private Column[] columns;

        /// <summary>
        /// Initializes a new instance of the ColumnCollection class,
        /// which takes parameter with type ColumnsAmount 
        /// and initialize instances in array of Column.
        /// </summary>
        /// <param name="amount">amount of columns</param>
        public ColumnCollection(ColumnsAmount amount)
        {
            this.columnAmount = amount;
            this.columns = new Column[(int)amount];

            switch (amount)
            {
                case (ColumnsAmount.ThreeColumn):
                    this.columns[0] = new Column(Statuses.New);
                    this.columns[1] = new Column(Statuses.InProgress);
                    this.columns[2] = new Column(Statuses.Done);
                    break;

                case (ColumnsAmount.OneColumn):
                    this.columns[0] = new Column();
                    break;
            }
        }

        /// <summary>
        /// Gets amount of columns in column collection
        /// </summary>
        public ColumnsAmount ColumnAmount
        {
            get
            {
                return this.columnAmount;
            }
        }

        /// <summary>
        /// Indexer, that gives an ability to access the column by status
        /// </summary>
        /// <param name="status">Represents a status of column</param>
        /// <returns>Instance of Column class in column collection, 
        /// which has a specified status</returns>
        public Column this[Statuses status]
        {
            get
            {
                return this.GetColumn(status);
            }
        }

        /// <summary>
        /// Indexer method, that gets column by status
        /// </summary>
        /// <param name="status">Status of column to search</param>
        /// <returns>Instance of Column class in column collection, 
        /// which has a specified status</returns>
        private Column GetColumn(Statuses status)
        {
            foreach (Column column in this.columns)
            {
                if (column.Status == status)
                {
                    return column;
                }
            }

            throw new System.ArgumentOutOfRangeException(status.ToString(), " value must be in Statuses enum");
        }
    }
}
